package com.ft.springboottravel.service.impl;


import com.ft.springboottravel.bean.Route;
import com.ft.springboottravel.mapper.RouteMapper;
import com.ft.springboottravel.service.RouteService;
import com.ft.springboottravel.util.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RouteServiceImpl implements RouteService {


    @Autowired
    private RouteMapper routeMapper;

    @Override
    public Pager<Route> selectRouteList(String titleName,Integer shop_id, Integer cate_id,  Integer currentPage) {

        if(currentPage == null || currentPage < 0){
            currentPage = 1;
        }

        Pager<Route> pager = new Pager<>();

        pager.setPageSize(4);

        pager.setList(routeMapper.selectRouteList(titleName,shop_id,cate_id,(currentPage-1)*4));

        pager.setCurrentPage(currentPage);

        pager.setTotal(routeMapper.getTotal(titleName,shop_id,cate_id));

        return pager;
    }

    @Override
    public Route toRoute(Integer routeId) {
        return routeMapper.toRoute(routeId);
    }

    @Override
    public Route selectRoute(Integer routeId) {
        return routeMapper.selectRoute(routeId);
    }

    @Override
    public void addRoute(Route route) {
        routeMapper.addRoute(route);
    }

    @Override
    public void editRoute(Route route) {
        routeMapper.editRoute(route);
    }

    @Override
    public void deleteRoute(Integer routeId) {
        routeMapper.deleteRoute(routeId);
    }

}
